package psbc.daily.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import psbc.daily.entity.Category;
import psbc.daily.result.Result;
import psbc.daily.service.CategoryService;

import java.util.List;

@RestController
@RequestMapping("/category")
@Slf4j
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @GetMapping()
    public Result<List<Category>> getAll()
    {
        List<Category> list = categoryService.list();
        return Result.success(list);
    }

    @GetMapping("/{categoryId}")
    public int DeleteCategoryById(@PathVariable int categoryId){
        log.info("删除分类id:{}",categoryId);
        return categoryService.delById(categoryId);
    }

    @PostMapping("/add")
    public int addCategory(@RequestBody Category category)
    {
        log.info("添加分类:{}",category);
        return categoryService.insert(category);
    }
}
